package com.lzq.model.decorator;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/22 19:17
 * @updateUser : modify
 * @updateTime : 2022/11/22 19:17
 * @updateRemark : 装饰者模式
 */
public abstract class FastFood {
    private float price;
    private String desc;

    public FastFood(float price, String desc) {
        this.price = price;
        this.desc = desc;
    }

    public float getPrice() {
        return price;
    }

    public String getDesc() {
        return desc;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 计算总价
     *
     * @return float
     */
    public abstract float count();
}

class FriedRice extends FastFood {

    public FriedRice() {
        super(10, "炒饭");
    }

    @Override
    public float count() {
        return getPrice();
    }
}

class FriedNoodles extends FastFood {

    public FriedNoodles() {
        super(12, "炒面");
    }

    @Override
    public float count() {
        return getPrice();
    }
}

abstract class Garnish extends FastFood {
    private FastFood fastFood;

    public FastFood getFastFood() {
        return fastFood;
    }

    public void setFastFood(FastFood fastFood) {
        this.fastFood = fastFood;
    }

    public Garnish(float price, String desc, FastFood fastFood) {
        super(price, desc);
        this.fastFood = fastFood;
    }
}

class Egg extends Garnish {

    public Egg(FastFood fastFood) {
        super(1, "鸡蛋", fastFood);
    }

    public float count() {
        return super.getPrice() + getFastFood().getPrice();
    }

    @Override
    public String getDesc() {
        return super.getDesc() + getFastFood().getDesc();
    }
}

class Bacon extends Garnish {
    public Bacon(FastFood fastFood) {
        super(3, "培根", fastFood);
    }

    public float count() {
        return super.getPrice() + getFastFood().getPrice();
    }

    @Override
    public String getDesc() {
        return super.getDesc() + getFastFood().getDesc();
    }
}

class Test {
    public static void main(String[] args) {
        FastFood fastFood = new FriedRice();
        System.out.println(fastFood.getDesc() + "===>>>>" + fastFood.count());

        fastFood = new Egg(fastFood);
        System.out.println(fastFood.getDesc() + "===>>>>" + fastFood.count());
    }
}